﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ehost
{
    public partial class AddHostForm : Form
    {
        private mainForm mainForm;
        private int type;
        public AddHostForm(mainForm form,int type)
        {
            mainForm = form;
            this.type = type;
            InitializeComponent();
        }

        private void AddHostForm_Load(object sender, EventArgs e)
        {
            if (type == 1)
            {
                textBox2.Text= mainForm.getTreeView().SelectedNode.Text;
                textBox2.Enabled = false;
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Host host = new Host();
            host.ip = textBox1.Text;
            host.domain = textBox2.Text;
            host.comment = textBox3.Text;

            if (checkBox1.Checked == true) host.able = true;
            else host.able = false;

            if (type == 1)
            {
                TreeNode tn = new TreeNode();
                tn.Text = host.ip;
                tn.Tag = host;
                tn.Checked = host.able;
                mainForm.getTreeView().SelectedNode.Nodes.Add(tn);
                
            }
            else if (type == 2)
            {
                TreeNode tnsub = new TreeNode();
                tnsub.Text = host.ip;
                tnsub.Tag = host;
                tnsub.Checked = host.able;

                TreeNode tn = new TreeNode();
                tn.Text = host.domain;
                tn.Checked = host.able;
                tn.Nodes.Add(tnsub);
                mainForm.getTreeView().Nodes.Add(tn);
            }

            mainForm.addNewHost(host);
            Close();
        }

     

      
    }
}
